package com.example.system.controller;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.common.core.enums.StudentStatusEnum;
import com.example.system.domain.student.dto.StudentDTO;
import com.example.system.domain.student.dto.StudentSaveDTO;
import com.example.system.domain.student.dto.StudentQueryDTO;
import com.example.system.domain.student.dto.StudentClassroomDTO;
import com.example.system.domain.student.vo.StudentDetailVO;
import com.example.system.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController extends BaseController {
    @Autowired
    private IStudentService studentService;

    @GetMapping("/list")
    public TableDataInfo list(StudentQueryDTO studentQueryDTO) {
        return getTableDataInfo(studentService.list(studentQueryDTO));
    }

    //  /student/detail
    @GetMapping("/detail")
    public R<StudentDetailVO> detail(Long studentId) {
        return R.ok(studentService.detail(studentId));
    }

    //  /student/edit
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody StudentSaveDTO studentSaveDTO) {
        return toR(studentService.edit(studentSaveDTO));
    }

    // /student/updateStatus
    @PutMapping("/updateStatus")
    public R<Void> updateStatus(@RequestBody StudentDTO studentDTO) {
        return toR(studentService.updateStatus(studentDTO));
    }
    
    /**
     * 禁言学生
     */
    @PutMapping("/mute")
    public R<Void> muteStudent(Long studentId) {
        StudentDTO studentDTO = new StudentDTO();
        studentDTO.setStudentId(studentId);
        studentDTO.setStatus(StudentStatusEnum.MUTED.getCode());
        return toR(studentService.updateStatus(studentDTO));
    }
    
    /**
     * 拉黑学生
     */
    @PutMapping("/blacklist")
    public R<Void> blacklistStudent(Long studentId) {
        StudentDTO studentDTO = new StudentDTO();
        studentDTO.setStudentId(studentId);
        studentDTO.setStatus(StudentStatusEnum.BLACKLISTED.getCode());
        return toR(studentService.updateStatus(studentDTO));
    }
    
    /**
     * 恢复学生正常状态
     */
    @PutMapping("/restore")
    public R<Void> restoreStudent(Long studentId) {
        StudentDTO studentDTO = new StudentDTO();
        studentDTO.setStudentId(studentId);
        studentDTO.setStatus(StudentStatusEnum.NORMAL.getCode());
        return toR(studentService.updateStatus(studentDTO));
    }
    
    /**
     * 更新学生所属班级
     */
    @PutMapping("/updateClassroom")
    public R<Void> updateClassroom(@RequestBody StudentClassroomDTO studentClassroomDTO) {
        return toR(studentService.updateClassroom(studentClassroomDTO));
    }
}
